package com.huasoft.servlet.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huasoft.dao.UserDao;
import com.huasoft.domain.User;

public class UpdateUserServlet {
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		User user = new User();
		user.setId(Integer.parseInt(request.getParameter("id")));
		user.setLoginname(request.getParameter("loginname"));
		user.setPassword(request.getParameter("password"));
		user.setName(request.getParameter("name"));
		user.setAge(Integer.parseInt(request.getParameter("age")));
		user.setGender(request.getParameter("gender"));
		user.setBirthday(request.getParameter("birthday"));
		user.setDeptid(Integer.parseInt(request.getParameter("deptid")));
		user.setRoleid(Integer.parseInt(request.getParameter("roleid")));
		UserDao userDao = new UserDao();
		boolean update = userDao.update(user);
		if (update) {
			request.setAttribute("msg_updateUserSuccess", "更新用户成功");
		} else {
			request.setAttribute("msg_updateUserFalse", "更新用户失败");
		}
		request.getRequestDispatcher("/index.jsp").forward(request, response);

	}
}
